import Cookies from 'js-cookie';

export { Cookies };

// 鉴权token
export function getToken(key?: string): string | undefined {
  return Cookies.get(key || 'token');
}

export function setToken(token: string, expires?: number, key?: string): undefined {
  if (expires) {
    Cookies.set(key || 'token', token, { expires: new Date(new Date().getTime() + expires * 1000) }); // 秒
  } else {
    Cookies.set(key || 'token', token);
  }
}

export function removeToken(key?: string): void {
  Cookies.remove(key || 'token');
}
